package ac.il.technion.c236369.hw4.core;

import java.net.Socket;

import org.apache.log4j.Logger;

import ac.il.technion.c236369.hw4.core.queues.ServerRequestsQueue;
import ac.il.technion.c236369.hw4.core.queues.SocketQueue;

/**
 * @author @author Artem Barger, Maxim Aizenshtein.
 * 
 * SocketReader, once in a while socket reader responsibility
 * to lookup sockets queue and in case there is pending
 * socket serve corresponding request.
 *
 */
public class SocketReader extends ServerRunnableEntity {

	public SocketReader( ) {
		setUpLogger(Logger.getLogger( Socket.class));
	}
	
	@Override
	public void runImpl() {
		Socket socket = SocketQueue.getInstance().get( );
		if ( socket == SocketQueue.NULL_SOCKET)
			return;
		ServerRequest request = new ServerRequest( socket);
		ServerRequestsQueue.getInstance().tryAdd(request);
	}

}
